#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 30;
ll m, n;
ll pw2[N];
void init()
{
    pw2[0] = 1;
    for (int i = 1; i < N; i++)
        pw2[i] = pw2[i - 1] << 1ll;
}
int main()
{
    int t;
    init();
    scanf("%d", &t);
    while (t--)
    {
        scanf("%lld", &n);
        int cnt = 0;
        int i;
        for (i = 0; i < N; i++)
        {
            if (n - pw2[i] >= 0)
            {
                n -= pw2[i];
                cnt++;
            }
            else
                break;
        }
        for (; i >= 0; i--)
        {
            while (n - pw2[i] >= 0)
            {
                n -= pw2[i];
                cnt++;
            }
        }

        printf("%d\n", cnt);
    }
    return 0;
}